<%@ include file="../base/include.jsp"%>

<div class="well registration-form">
	<div class="page-header">
		<h3>Registration</h3>
	</div>
	<form:form class="form-vertical" commandName="userCommand">
		<c:if test="${not empty errorMessage}">
			<div class="control-group" align="left" style="background-color: red">
				${errorMessage}
			</div>
		</c:if>
		<div class="control-group">
			<label>Nickname (will be used as your login):</label>
			<form:input class="user-form-input" path="username" />
			<form:errors path="username" />
		</div>
		<div class="control-group">
			<label>Password:</label>
			<form:password class="user-form-input" path="newPassword" />
			<label>Confirm Password:</label> 
			<form:password class="user-form-input" path="confirmedPassword" />
			<form:errors path="newPassword" />
		</div>
		<div class="control-group">
			<label>Email:</label>
			<form:input class="user-form-input" path="email" />
			<form:errors path="email" />
		</div>
		<div class="control-group">
			<label>Full Name:</label>
			<form:input class="user-form-input" path="name" />
			<form:errors path="name" />
		</div>
		<div class="control-group">
			<button type="submit" formmethod="post"
				formaction="<c:url value='/register'/>" class="btn btn-primary">Register</button>
		</div>
		<div class="row control-group">
			<a style="float: right;" href="<c:url value='/' />">To login page</a>
		</div>

	</form:form>
</div>

<script type="text/javascript">
	var mail = new LiveValidation('mail', {
		validMessage : ' ',
		onlyOnBlur : true
	});
	mail.add(Validate.Presence, {
		failureMessage : "Email cannot be empty."
	});
	mail.add(Validate.Email, {
		failureMessage : 'Email address is incorrect.'
	});

	var password = new LiveValidation('password', {
		validMessage : ' ',
		onlyOnBlur : true
	});
	password.add(Validate.Presence, {
		failureMessage : "Password can't be empty."
	});

	var confirmedPassword = new LiveValidation('confirmed_password', {
		validMessage : ' ',
		onlyOnBlur : true
	});
	confirmedPassword.add(Validate.Presence, {
		failureMessage : "Please, confirm password."//"Password confirmation can't be empty."
	});
	confirmedPassword.add(Validate.Confirmation, {
		match : 'password',
		failureMessage : "Passwords don't match!"
	});
</script>